import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { RuleVO, RuleForm, RuleQuery } from '@/api/kitchen/product/rule/types';

/**
 * 查询商品规则值(规格)列表
 * @param query
 * @returns {*}
 */

export const listRule = (query?: RuleQuery): AxiosPromise<RuleVO[]> => {
  return request({
    url: '/kitchen/product/rule/list',
    method: 'get',
    params: query
  });
};


// 查询商品规则值(规格)列表
export const listNoPageRule = (ruleId) => {
  if(ruleId  == undefined || ruleId == ''){
    ruleId = 0;
  }
  return request({
    url: '/kitchen/product/rule/listNoPage/' + ruleId,
    method: 'get'
  });
};

/**
 * 查询商品规则值(规格)详细
 * @param id
 */
export const getRule = (id: string | number): AxiosPromise<RuleVO> => {
  return request({
    url: '/kitchen/product/rule/' + id,
    method: 'get'
  });
};

/**
 * 新增商品规则值(规格)
 * @param data
 */
export const addRule = (data: RuleForm) => {
  return request({
    url: '/kitchen/product/rule',
    method: 'post',
    data: data
  });
};

/**
 * 修改商品规则值(规格)
 * @param data
 */
export const updateRule = (data: RuleForm) => {
  return request({
    url: '/kitchen/product/rule',
    method: 'put',
    data: data
  });
};

/**
 * 删除商品规则值(规格)
 * @param id
 */
export const delRule = (id: string | number | Array<string | number>) => {
  return request({
    url: '/kitchen/product/rule/' + id,
    method: 'delete'
  });
};
